<?php
namespace Shopiuu\Model;

use Shopiuu\Http\RequestCore;

class EmbedCode extends Model{
    
    public function __construct($accessToken, $endpoint)
    {
        parent::__construct($accessToken, $endpoint);
    }

    /**
     * Create embed code
     * @param array $params array(
            [name] => Hide price
            [details] => <style>.price{display:none;}</style>
            [position] => BODY_BOTTOM
            [page_code] => 
            [status] => 1
            [only_show_once] => N
        )
     * @return ResponseCore
     */
    public function add($params)
    {
        $request = $this->getRequest('/openApi/embedCode/add');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Modify embed code
     * @param array $paramss array(
            [id] => 1
            [name] => Hide price
            [details] => <style>.price{display:none;}</style>
            [position] => BODY_BOTTOM
            [page_code] => 
            [status] => 1
            [only_show_once] => N
        )
     * @return ResponseCore
     */
    public function update($params)
    {
        $request = $this->getRequest('/openApi/embedCode/update');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Get embed code
     * @param array $params array(
        "pagenum"=> 1 //页码
        "pagesize"=> 20 //每页数量
        "search"=> "keywords" //搜索标题
        "position"=> "BODY_BOTTOM" //搜索位置编码
        "page_code"=> "checkout_success" //搜索页面编码
        "orderfeild"=> "id" //排序字段
        "ordersort"=> "desc" //排序方式
     )
     * @return ResponseCore
     */
    public function getList($params)
    {
        $request = $this->getRequest('/openApi/embedCode/lists');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }
    
    /**
     * Delete embed code
     * @param array $params array("id"=>"25")
     * @return ResponseCore
     */
    public function delete($params)
    {
        $request = $this->getRequest('/openApi/embedCode/delete');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

}